package main

import (
	"context"
	"github.com/chromedp/chromedp"
	"log"
	"strings"
	"time"
)

func main() {
	opts := append(chromedp.DefaultExecAllocatorOptions[:],
		chromedp.Flag("headless", false),
	)

	allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
	defer cancel()

	// also set up a custom logger
	ctx, cancel := chromedp.NewContext(allocCtx, chromedp.WithLogf(log.Printf))
	defer cancel()

	attrMap := make(map[string]string)
	attrMap["value"] = "1111111"

	// run task list
	var res string
	err := chromedp.Run(ctx,
		chromedp.Navigate("https://www.windhc.com/unix-timestamp"),
		//chromedp.Text(`.footer`, &res, chromedp.NodeVisible, chromedp.ByQuery),
		chromedp.Sleep(1*time.Second),
		//chromedp.Click(`#app > div > div.main > div:nth-child(2) > div:nth-child(8) > a`, chromedp.ByQuery),
		//chromedp.SetAttributes(`#content`, attrMap, chromedp.ByQuery),
		chromedp.Sleep(10*time.Millisecond),
		chromedp.Click(`#content`, chromedp.ByQuery),
		chromedp.Sleep(3*time.Second),
	)

	chromedp.Run(ctx,
		chromedp.Click(`#to-beijing-time`, chromedp.ByQuery),
		chromedp.Sleep(1*time.Second))

	if err != nil {
		log.Fatal(err)
	}
	log.Println(strings.TrimSpace(res))
	log.Println(attrMap)
}
